

//import bean.IndustryBean;
//import bean.ListedBean;
//import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;
//import utils.DBUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @program: Project
 * @className BigDataIndexServlet
 * @description:
 * @author: DZH
 * @create: 2023-09-21 08:16
 * @Version 1.0
 **/
@WebServlet("/bigDataIndexServlet")
public class BigDataIndexServlet  extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置请求和响应的编码格式
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");


        //拿到上市公司的两个数值
        String sql = "select * from listed_tb where id=1;";
        bean.ListedBean listedBean = utils.DBUtils.updateQuery(bean.ListedBean.class, sql);
        System.out.println(listedBean);


        //创建Json字符串 {xxx:xxx}
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("countryNum",listedBean.getCountry_num());
        jsonObject.put("shanxiNum",listedBean.getShanxi_num());


        //获取行业权重
        String sql2 = "select * from industry_tb;";
        List<IndustryBean> industryBeans = utils.DBUtils.publicQueryList(IndustryBean.class, sql2);

        JSONObject industryObject = new JSONObject();

        JSONArray industryNameArray = new JSONArray();
        JSONArray industryNumArray = new JSONArray();
        for (int i = 0; i < industryBeans.size(); i++) {
            IndustryBean industryBean = industryBeans.get(i);
            industryNameArray.add(industryBean.getName());
            industryNumArray.add(industryBean.getNum());
        }
        industryObject.put("industryNameArray",industryNameArray);
        industryObject.put("industryNumArray",industryNumArray);

        jsonObject.put("industryObject",industryObject);

        //返回前端数据
        resp.getWriter().write(jsonObject.toString());


    }
}
